<script>
import {sendRequest} from "@/util/request";

export default {
  name: "MainInfo",
  data() {
    return {
      countCustomer: '',
      countOrders: '',
      countAmount: '',
      countProduct: '',
      productsOfConsume: [],
      customersOfConsume: [],
      menuList: [],
    };
  },
  created() {
    this.getCountOrders();
    this.getCountCustomer();
    this.getCountAmount();
    this.getCountProduct();
    this.selectCustomersOfConsume();
    this.selectProductsOfConsume();
  },
  methods: {
    selectProductsOfConsume() {
      sendRequest(
          "post",
          "product/productsOfConsume",
      ).then(res => {
        console.log(res);
        this.productsOfConsume = res.list;
      })
    },
    selectCustomersOfConsume() {
      sendRequest(
          "post",
          "customer/selectCustomersOfConsume",
      ).then(res => {
        this.customersOfConsume = res.list;
      })
    },
    getCountCustomer() {
      sendRequest(
          "post",
          "customer/countCustomer",
      ).then(res => {
        this.countCustomer = res.msg;
      })
    },
    getCountAmount() {
      sendRequest(
          "post",
          "order/countAmount",
      ).then(res => {
        this.countAmount = res.msg;
      })
    },
    getCountOrders() {
      sendRequest(
          "post",
          "order/countOrders",
      ).then(res => {
        this.countOrders = res.msg;
      })
    },
    getCountProduct() {
      sendRequest(
          "post",
          "product/accountProduct",
      ).then(res => {
        this.countProduct = res.msg;
      })
    },
  }
};
</script>

<template>
  <div>
    <el-container>
      <el-header style="text-align: left; background-color: #fff;">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/mainInfo' }">首页</el-breadcrumb-item>
        </el-breadcrumb>
      </el-header>
      <el-main>

        <el-row :gutter="20">
          <el-col :span="6">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>会员总数</span>
              </div>
              <div>{{ countCustomer }}</div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>订单总数</span>
              </div>
              <div>{{ countOrders }}</div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>总金额</span>
              </div>
              <div>{{ countAmount }}</div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>商品总数</span>
              </div>
              <div>{{ countProduct }}</div>
            </el-card>
          </el-col>
        </el-row>
        <el-row :gutter="20" style="margin-top: 20px;">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>商品销售排行</span>
              </div>
              <el-table :data="productsOfConsume" style="width: 100%">
                <el-table-column prop="id" label="ID"></el-table-column>
                <el-table-column prop="productName" label="商品名称"></el-table-column>
                <el-table-column prop="salesVolume" label="销量"></el-table-column>
              </el-table>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>用户消费排行</span>
              </div>
              <el-table :data="customersOfConsume" style="width: 100%">
                <el-table-column prop="id" label="ID"></el-table-column>
                <el-table-column prop="nicknameCustomer" label="用户名"></el-table-column>
                <el-table-column prop="accountAmount" label="消费金额"></el-table-column>
              </el-table>
            </el-card>
          </el-col>
        </el-row>
      </el-main>
    </el-container>
  </div>
</template>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

.el-header {
  background-color: #fff;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>